package com.ruoyi.web.controller.consume;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consume.domain.GraftingclipApplyTemporaryCon;
import com.ruoyi.consume.service.IGraftingclipApplyTemporaryConService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 嫁接夹临时领用Controller
 *
 * @author ruoyi
 * @date 2021-07-27
 */
@Api("嫁接夹临时领用")
@RestController
@RequestMapping("/consume/graftingcliptemap")
public class GraftingclipApplyTemporaryConController extends BaseController
{
    @Autowired
    private IGraftingclipApplyTemporaryConService graftingclipApplyTemporaryService;

    /**
     * 查询嫁接夹临时领用列表
     */
    @ApiOperation("查询嫁接夹临时领用列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:graftingcliptemap:list')")
    @GetMapping("/list")
    public TableDataInfo list(GraftingclipApplyTemporaryCon graftingclipApplyTemporaryCon)
    {
        startPage();
        List<GraftingclipApplyTemporaryCon> list = graftingclipApplyTemporaryService.selectGraftingclipApplyTemporaryList(graftingclipApplyTemporaryCon);
        return getDataTable(list);
    }

    /**
     * 导出嫁接夹临时领用列表
     */
    @PreAuthorize("@ss.hasPermi('consume:graftingcliptemap:export')")
    @Log(title = "嫁接夹临时领用", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GraftingclipApplyTemporaryCon graftingclipApplyTemporaryCon)
    {
        List<GraftingclipApplyTemporaryCon> list = graftingclipApplyTemporaryService.selectGraftingclipApplyTemporaryList(graftingclipApplyTemporaryCon);
        ExcelUtil<GraftingclipApplyTemporaryCon> util = new ExcelUtil<GraftingclipApplyTemporaryCon>(GraftingclipApplyTemporaryCon.class);
        return util.exportExcel(list, "嫁接夹临时领用数据");
    }

    /**
     * 获取嫁接夹临时领用详细信息
     */
    @PreAuthorize("@ss.hasPermi('consume:graftingcliptemap:query')")
    @GetMapping(value = "/{graftingclipApplyTemporaryId}")
    public AjaxResult getInfo(@PathVariable("graftingclipApplyTemporaryId") Long graftingclipApplyTemporaryId)
    {
        return AjaxResult.success(graftingclipApplyTemporaryService.selectGraftingclipApplyTemporaryById(graftingclipApplyTemporaryId));
    }

    /**
     * 新增嫁接夹临时领用
     */
    @PreAuthorize("@ss.hasPermi('consume:graftingcliptemap:add')")
    @Log(title = "嫁接夹临时领用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GraftingclipApplyTemporaryCon graftingclipApplyTemporaryCon)
    {
        return toAjax(graftingclipApplyTemporaryService.insertGraftingclipApplyTemporary(graftingclipApplyTemporaryCon));
    }

    /**
     * 修改嫁接夹临时领用
     */
    @PreAuthorize("@ss.hasPermi('consume:graftingcliptemap:edit')")
    @Log(title = "嫁接夹临时领用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GraftingclipApplyTemporaryCon graftingclipApplyTemporaryCon)
    {
        return toAjax(graftingclipApplyTemporaryService.updateGraftingclipApplyTemporary(graftingclipApplyTemporaryCon));
    }

    /**
     * 删除嫁接夹临时领用
     */
    @PreAuthorize("@ss.hasPermi('consume:graftingcliptemap:remove')")
    @Log(title = "嫁接夹临时领用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{graftingclipApplyTemporaryIds}")
    public AjaxResult remove(@PathVariable Long[] graftingclipApplyTemporaryIds)
    {
        return toAjax(graftingclipApplyTemporaryService.deleteGraftingclipApplyTemporaryByIds(graftingclipApplyTemporaryIds));
    }

    /**
     * 更新库存量表
     */
    @ApiOperation("更新库存量表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:graftingcliptemap:amount')")
    @Log(title = "嫁接夹临时领用", businessType = BusinessType.UPDATE)
    @PutMapping("/amount")
    public AjaxResult amount(@RequestBody GraftingclipApplyTemporaryCon graftingclipApplyTemporaryCon)
    {
        return toAjax(graftingclipApplyTemporaryService.updateAmount(graftingclipApplyTemporaryCon));
    }

    /**
     * 更新领用状态
     */
    @ApiOperation("更新领用状态")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:graftingcliptemap:consu')")
    @Log(title = "嫁接夹临时领用", businessType = BusinessType.UPDATE)
    @PutMapping("/consu/{graftingclipApplyTemporaryId}")
    public AjaxResult consume(@PathVariable("graftingclipApplyTemporaryId") Long graftingclipApplyTemporaryId)
    {
        return toAjax(graftingclipApplyTemporaryService.updateConsumeStatus(graftingclipApplyTemporaryId));
    }

    /**
     * 退回操作
     */
    @ApiOperation("退回操作")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:graftingcliptemap:back')")
    @Log(title = "嫁接夹临时领用", businessType = BusinessType.UPDATE)
    @PutMapping("/back/{graftingclipApplyTemporaryId}")
    public AjaxResult back(@PathVariable("graftingclipApplyTemporaryId") Long graftingclipApplyTemporaryId)
    {
        return toAjax(graftingclipApplyTemporaryService.updateApprovalStatus(graftingclipApplyTemporaryId));
    }
}
